<template>
  <div>
    <h1 style="font-size: 40px">添加学生</h1>
    <p style="font-size: 20px">欢迎您{{ tea.name }}</p>
    <p>学生姓名：<input type="text" v-model="form.name"></p>
    <p>年&nbsp;&nbsp;龄<input type="text" v-model="form.age"></p>
    <button @click="addstu">提交</button>
    <router-link :to="{name:'getstu'}">点击查看您班级的学生</router-link>
    <router-link :to="{name:'nostu'}">点击查看未分班的学生</router-link>
  </div>
</template>

<script>
export default {
  name: "addstu",
  data() {
    return {
      tea: {},
      userid: localStorage.getItem('userid'),
      form: {'tea': localStorage.getItem('userid')}
    }
  },
  methods: {
    get_tea() {
      this.$axios.get('tea/?userid=' + this.userid)
        .then(res => {
          this.tea = res.data.list

        })
    },
    addstu() {
      this.$axios.post('stu/', this.form)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
          }

        })
    }
  },
  mounted() {
    this.get_tea()
  }
}
</script>

<style scoped>

</style>
